********************************************************************************
** Do file: g9_compliershare.do
** First started: November 5, 2020 
** Last edited: September 8, 2023

/* Purpose: this do file calculates complier shares by treatment group

* ITEM MADE: TABLE A.8
*/

********************************************************************************

clear
clear matrix
clear mata
set maxvar 10000

* Note: for the Adverse selection comparison, have to use complier_share* on T1-U and lockout_share* on T2-U

* Call dataset
use "$repay_clean/fenix_repay_extend_07172020_rep.dta", clear

* Generate a compliance variable, used to compare Surprise Unsecured to Unsecured
g locked_share_wupg_AS = .
replace locked_share_wupg_AS = complier_share_wupg if treatmenttype_sh=="R T1-U"
replace locked_share_wupg_AS = locked_share_wupg if treatmenttype_sh=="R T2-U"

* Keep those according the consort procedure
merge m:1 accountid using "$merged/key_rep.dta", keepusing(k_complete_may k_rolling_list k_interacted_success k_tookloan_repay)
keep if _merge==3 & k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_tookloan_repay==1

* Keep to sample groups of interest
keep if treatmenttype_sh=="R T1-L" | treatmenttype_sh=="R T1-U" | treatmenttype_sh=="R T2-U"

* Keep to specific days
keep if loandayselapsed==50 | loandayselapsed==100 | loandayselapsed==150 | loandayselapsed==200

* Develop a variable that will capture just the standard deviation of compliance
g complier_share_wupgsd = complier_share_wupg

***** TABLE A.9 *****
collapse (mean) complier_share_wupg (sd) complier_share_wupgsd, by(treatmenttype_sh loandayselapsed)
* List
list
